package com.example.teststarter.service;

import com.example.teststarter.entity.User;
import com.example.teststarter.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class OtherService {
	@Autowired
	UserMapper userMapper;
	
	//新增
	@Transactional(propagation = Propagation.REQUIRES_NEW)
    public boolean insertUser() {
    	 /*
    	 //普通for循环插入
    	 for (int i = 0; i <20; i++) {
    	    User user = new User();
    		user.setId(i);
    		user.setUserName("testusername" + i);
    		user.setPassWord("testpassword" + i);
	        user.setRealName("testrealname"+i);
    		userMapper.insertUser(user);
    	  }
    	  */
    	//userMapper.insertUser(user);
    	List<User> list = new ArrayList<>();
    	for (int i = 10; i <15; i++) {
    	    User user = new User();
    		user.setId(i);
    		user.setUserName("*username" + i);
    		user.setPassWord("*password*"+i);
    		user.setRealName("*realname*"+i);
    		list.add(user);
        }
    	userMapper.insertUser(list);
        return true;
    }

}
